﻿using Icst.Leaflike.Searching;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Icst.Leaflike;
using System;
using System.IO;
using System.Threading;

namespace Icst.Leaflike.Test
{
    
    
    /// <summary>
    ///This is a test class for SearchServiceTest and is intended
    ///to contain all SearchServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SearchServiceTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SearchContours
        ///</summary>
        [TestMethod()]
        public void SearchContoursTest()
        {
            SearchService target = new SearchService();
            byte[] bytes = new byte[] { 1};
            Contour[] actual = target.SearchContours(bytes);
            Assert.IsNotNull(actual);
            Assert.AreEqual(3,actual.Length);

            foreach (var c in actual)
            {
                Console.WriteLine("***********************************************************8");
                Console.WriteLine(c.ToString());
            }
        }

        /// <summary>
        ///A test for SearchPlants
        ///</summary>
        [TestMethod()]
        public void SearchPlantsTest()
        {
            SAFGWrapper.Initialize(Path.Combine(Thread.GetDomain().BaseDirectory, "SAFG.cache"), Path.Combine(Thread.GetDomain().BaseDirectory, "SAFG.clist"));

            SearchService target = new SearchService(); 
            Contour[] cs = target.SearchContours(new byte[]{1});

            Contour contour = cs[0];
            int maxcount = 10;

            Plant[] ps = target.SearchPlants(contour, maxcount);

            Assert.IsNotNull(ps);

            foreach (var p in ps) { Console.Write("{0},{1}", p.ID, p.Name); }
        }
    }
}
